const arr = [5,7,1,8,1,8,3,4,9,7];
function unique(arr) {
  arr = arr.sort()
  console.log(arr);
  let arr1 = [arr[0]]
  for(let i = 1; i < arr.length; i++) {
    if(arr[i] !== arr[i-1]) {
      arr1.push(arr[i])
    }
  }
  console.log(arr1);
  return arr1
}
// unique(arr)

// 数组去重
// es5-filter
function deduplication1(arr) {
  return arr.filter((item, index) => {
    return arr.indexOf(item) === index
  })
}
// console.log(deduplication1(arr));
// es6-set
function deduplication2(arr) {
  return Array.from(new Set(arr))
}
console.log(deduplication2(arr));
console.log([...new Set(arr)]);